package io.geekidea.boot.materialrule.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.geekidea.boot.common.PageDto;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.materialrule.dto.addMaterialRule;
import io.geekidea.boot.materialrule.dto.updateMaterialRule;
import io.geekidea.boot.materialrule.entity.MaterialRule;
import io.geekidea.boot.materialrule.query.MaterialRuleQuery;
import io.geekidea.boot.materialrule.service.MaterialRuleService;
import io.geekidea.boot.otherstores.entity.OtherStores;
import io.geekidea.boot.otherstores.query.OtherQuery;
import io.geekidea.boot.payment.entity.Payment;
import io.geekidea.boot.payment.query.PaymentQuery;
import io.geekidea.boot.warehousentry.query.WarehousentryQuery;
import io.geekidea.boot.warehousentry.query.entity.Warehousentry;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("MaterialRule")
@Tag(name="物料超期规则")
public class MaterialRuleController {
    @Resource
    private MaterialRuleService materialRuleService;


//    @PostMapping("/search")
//    public ApiResult search(@RequestBody MaterialRuleQuery materialRuleQuery){
//        List<MaterialRule> list = materialRuleService.list();
//        Page<MaterialRule> page=new Page<>(materialRuleQuery.getPage(),materialRuleQuery.getSize());
//        LambdaQueryWrapper<MaterialRule> lambdaQueryWrapper=new LambdaQueryWrapper<>();
//        Page<MaterialRule> pageDto=materialRuleService.page(page,lambdaQueryWrapper);
//        PageDto<MaterialRule> pageInfo=new PageDto<>(pageDto.getRecords(),pageDto.getTotal(),pageDto.getSize(),pageDto.getCurrent());

//
//        Page<MaterialRule> page=new Page<>(materialRuleQuery.getPage(),materialRuleQuery.getSize());
//        LambdaQueryWrapper<MaterialRule> lambdaQueryWrapper=new LambdaQueryWrapper<>();
//        Page<MaterialRule> pageDto=materialRuleService.page(page,lambdaQueryWrapper);
//        PageDto<MaterialRule> pageInfo=new PageDto<>(pageDto.getRecords(),pageDto.getTotal(),pageDto.getSize(),pageDto.getCurrent());
//
//
//
//
//       return ApiResult.success(pageInfo);
//
//    }

    @PostMapping("/search")
    public ApiResult search(@RequestBody MaterialRuleQuery materialRuleQuery){
        Page<MaterialRule> page=new Page<>(materialRuleQuery.getPageIndex(),materialRuleQuery.getPageSize());
        LambdaQueryWrapper<MaterialRule> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        Page<MaterialRule> pageDto=materialRuleService.page(page,lambdaQueryWrapper);
        PageDto<MaterialRule> pageInfo=new PageDto<>(pageDto.getRecords(),pageDto.getTotal(),pageDto.getSize(),pageDto.getCurrent());
        return ApiResult.success(pageInfo);
    }




    @PostMapping("/addRule")
    public ApiResult addRule(@RequestBody addMaterialRule addMaterialRule){

        boolean b = materialRuleService.addMaterialRule(addMaterialRule);
        if (b){
            return ApiResult.success("物料规则添加失败");
        }
        return ApiResult.success("物料规则添加成功");

    }



    @PostMapping("/updateRule")
    public ApiResult updateRule(@RequestBody updateMaterialRule updateMaterialRule){

        boolean b = materialRuleService.updateMaterialRule(updateMaterialRule);
        if (b){
            return ApiResult.success("物料规则修改失败");
        }
        return ApiResult.success("物料规则修改成功");

    }



}
